from pandas import DataFrame
from api_push.base_push import PushData
from tools.base_tools import fetch_data
from loguru import logger


class Search_Kws_Push(PushData):
    def __init__(self, start_date, end_date, table_name):
        super().__init__(start_date, end_date, table_name)

    # 定义好提取单天的逻辑
    def get_one_day_data(self, day_str):
        # 配置信息
        list_all_data = []
        page = 1
        while True:
            url_search_kws = f"https://scapi.tayunapi.com/funcLog/searchList?start={day_str}&end={day_str}&page={page}&rows=50"
            logger.info(url_search_kws)
            # 获取并处理订单数据
            search_kws_data = fetch_data(url_search_kws)
            # 会遇到没有的数据,然后就可以退出了
            if search_kws_data["list"]:
                list_all_data += search_kws_data["list"]
                page += 1
            else:
                break
        df = DataFrame(list_all_data)
        df["day_str"] = day_str

        return df
